package reflect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Shirly on 2016/8/10.
 */
public class Mybbb {
    private List<String> name;

    public List getName(final List<String> list) {
        return (List) Proxy.newProxyInstance(Mybbb.class.getClassLoader(), new Class[] { List.class },
                new InvocationHandler() {
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        if ("size".equals(method.getName())) {
                            throw new UnsupportedOperationException();

                        }
                        else {
                            return method.invoke(list, args);
                        }
                    }
                });
    }

    public void setName(java.util.List list) {
        name = list;
    }

    public static void main(String[] args) {
        Mybbb mybbb = new Mybbb();
        java.util.List list = new ArrayList();
        list.add("1");
        list.add("2");
        System.out.println(list.size());
       List newList = mybbb.getName(list);
        Object obj = MyClass.class;
      mybbb.printClassName(obj);



    }
    void printClassName(Object obj) {
        System.out.println("Myclass de name is " +MyClass.class.getName());
    }
}
